//

export const get_image = (model, res_id, field) => {
  const baseURL = process.env.VUE_APP_BASE_API
  const imgUrl = '/web/image'
  if (!res_id) {
    return ''
  }
  return `${baseURL}${imgUrl}?model=${model}&id=${res_id}&field=${field}`
}

export const searchToDomainList = (searchResult, searchs) => {
  //
  const v2 = searchResult.reduce((acc, cur) => {
    const [n1, n2] = cur.split('.')
    const op = searchs[n1].filters[n2].domain
    if (!acc[n1]) {
      acc[n1] = {}
    }
    acc[n1][n2] = op
    return acc
  }, {})
  const v4 = Object.values(v2).reduce((acc, cur) => {
    const cur2 = Object.values(cur)
    // console.log('va4,cur2,', cur2)
    const ors =
      cur2.length > 0 ? Array.from(new Array(cur2.length - 1), item => '|') : []
    const cur3 = cur2.reduce((jacc, jcur) => {
      return [...jacc, ...jcur]
    }, [])
    return [...acc, ...ors, ...cur3]
  }, [])
  // console.log('v4', v4)
  // this.domain2 = v4

  return v4
}
